let signRuleFun = (ruleData: any) => {
  return {
    userAccount: [
      { required: true, message: '请输入想要注册的账号' }
    ],
    userPsd: [
        { required: true, message: '请输入密码' },
        {
          validator: (rule: any, value: string|number, callback: Function) => {
            if (ruleData.reUserPsd) {
              if (value === ruleData.reUserPsd) {
                ruleData.signFromRef.clearValidate(['reUserPsd'])
                callback()
              } else {
                callback(new Error('两次密码输入不一致'))
              }
            } else {
              callback()
            }
          },
          trigger:'blur'
        }
    ],
    reUserPsd: [
        { required: true, message: '请确认密码' },
        {
          validator: (rule: any, value: string|number, callback: Function) => {
            if (ruleData.userPsd) {
              if (value === ruleData.userPsd) {
                ruleData.signFromRef.clearValidate(['userPsd'])
                callback()
              } else {
                callback(new Error('两次密码输入不一致'))
              }
            } else {
              callback()
            }
          },
          trigger:'blur'
        }
    ],
    userEmail: [
        { required: true, message: '请输入邮箱' },
        {
          validator: (rule: any, value: string|number, callback: Function) => {
            let reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/
            if (reg.test((value + ''))) {
              callback()
            } else {
              callback(new Error('邮箱格式输入有误'))
            }
          },
          trigger:'blur'
        }
    ],
    emailAuthCode: [
        { required: true, message: '请输入验证码' },
        {
          validator: (rule: any, value: string|number, callback: Function) => {
            let a = (value + '')
            let b = (ruleData.emailAuthCode + '')
            if (a === b) {
              callback()
            } else {
              callback(new Error('验证码输入有误'))
            }
          },
          trigger:'blur'
        }
    ]
  }
}
let loginRuleFun = (ruleData: any) => {
  return {
    userAccount: [
      { required: true, message: '请输入账号' }
    ],
    userPsd: [
      { required: true, message: '请输入密码' }
    ],
    loginAuthCode: [
        {
          validator: (rule: any, value: string|number, callback: Function) => {
            let a = (value + '').toLocaleLowerCase()
            let b = (ruleData.authCode + '').toLocaleLowerCase()
            if (a === b) {
              callback()
            } else {
              callback(new Error('验证码输入有误'))
            }
          },
          trigger:'blur'
        }
    ]
  }
}

export {
  loginRuleFun,
  signRuleFun
}
